package com.application.spider.model;

import java.util.List;

import com.application.spider.entities.Email;
import com.application.spider.entities.RedSocial;
import com.application.spider.entities.Sede;
import com.application.spider.entities.regex.EmailRegex;
import com.application.spider.entities.regex.RedSocialRegex;
import com.application.spider.entities.regex.SedeRegex;
import com.application.spider.exception.ItemNotFoundException;
import com.application.spider.exception.PageNotFoundException;
import com.application.spider.model.alias.ManagerSinonimos;

public class RetrieveInstitucion extends RetrivierWeb {


	private RetrieveSedes		sede;
	private RetrieveRedSocial	redSocial;
	private RetrieveEmail		email;
	
	public RetrieveInstitucion(ManagerSinonimos managerSinonimos) {
		super(managerSinonimos);
		sede  =  new RetrieveSedes(managerSinonimos);
		redSocial = new RetrieveRedSocial(managerSinonimos);
		email = new RetrieveEmail(managerSinonimos);
	}
	public String retrieveName(String url,String page,String regexPage,Integer grupoIdPage,String charset,String regex) throws ItemNotFoundException, PageNotFoundException{
		String nombre = "";
		String dato = "";
		dato = getWebPageContent(url, page, regexPage, grupoIdPage, charset);
		if(!dato.isEmpty()){
			nombre = getValue("nombre",dato,regex,1);
		}else{
			throw new ItemNotFoundException("no se pudo encontrar la pagina web "+url+" con los limites '"+regexPage+"' y charset "+charset);
		}
		return nombre;
	}
	public List<Sede> retrieveSedes(SedeRegex sedeRegex,String charset) throws PageNotFoundException, ItemNotFoundException {
		return sede.retrieve(sedeRegex, charset);
	}
	public List<RedSocial> retrieveRedesSociales(RedSocialRegex redSocialRegex,String charset) throws PageNotFoundException, ItemNotFoundException {
		return redSocial.retrieve(redSocialRegex, charset);
	}
	public List<Email> retrieveEmails(EmailRegex emailRegex,String charset) throws PageNotFoundException, ItemNotFoundException {
		return email.retrieve(emailRegex, charset);
	}
	
}
